﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using TaobaoERP.Core.Common;

namespace TaobaoERP.BusinessTaobao.Common
{
    public class Signature
    {
        private static string code =AppSettings.CERT_CODE;// "fb8e87c0a3f511dd906c8613347b303b";//软件注册时获得,此值为公共帐号HelloWorld（donet）注册的值
        public static string DoSignature(SortedList mySL)
        {
            string result = null;

            //签名字段的生成，将CERT CODE和所有接口要传的参数进行组合，再将组装好的字符串进行md5加密后转成16进制后得到一个32位的密文

            StringBuilder orgin = new StringBuilder();
            orgin.Append(code); //将安全编码放字符串首位
            //对list里的参数进行拼装，参数名+参数值，按自然排序，即所有参数字母排序
            foreach (DictionaryEntry Item in mySL)
            {
                ListItem newListItem = new ListItem();
                orgin.Append(Item.Key.ToString());
                if (Item.Value != null)
                {
                    orgin.Append(Item.Value.ToString());
                }
            }
            string tomd5str = orgin.ToString();
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            result = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(tomd5str))).Replace("-", "");//对拼装好的字符串进行md5加密
            return result;

        }
    }
}
